package com.fengze.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import com.fengze.business.enums.AuditStatusEnum;
import com.fengze.business.query.PaymentFinishReqParam;
import com.fengze.business.query.PaymentReqParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.fengze.common.annotation.Log;
import com.fengze.common.core.controller.BaseController;
import com.fengze.common.core.domain.AjaxResult;
import com.fengze.common.enums.BusinessType;
import com.fengze.business.domain.Payment;
import com.fengze.business.service.IPaymentService;
import com.fengze.common.utils.poi.ExcelUtil;
import com.fengze.common.core.page.TableDataInfo;

/**
 * 付款Controller
 * 
 * @author lug
 * @date 2024-12-10
 */
@RestController
@RequestMapping("/business/payment")
public class PaymentController extends BaseController
{
    @Autowired
    private IPaymentService paymentService;

    /**
     * 查询付款列表
     */
    @PreAuthorize("@ss.hasPermi('business:payment:list')")
    @GetMapping("/list")
    public TableDataInfo list(Payment payment)
    {
        startPage();
        List<Payment> list = paymentService.selectPaymentList(payment);
        return getDataTable(list);
    }

    /**
     * 查询审批中的付款列表
     */
    @PreAuthorize("@ss.hasPermi('business:payment:list')")
    @GetMapping("/list/processing")
    public TableDataInfo listProcessing(Payment payment)
    {
        payment.setAuditStatus(AuditStatusEnum.PROCESSING.getStatus());
        startPage();
        List<Payment> list = paymentService.selectPaymentList(payment);
        return getDataTable(list);
    }


    /**
     * 查询付款列表
     */
    @PreAuthorize("@ss.hasPermi('business:payment:list')")
    @GetMapping("/list/all")
    public AjaxResult list( @Valid  PaymentReqParam param)
    {
        return AjaxResult.success( paymentService.listAll(param));
    }


    /**
     * 导出付款列表
     */
    @PreAuthorize("@ss.hasPermi('business:payment:export')")
    @Log(title = "付款", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Payment payment)
    {
        List<Payment> list = paymentService.selectPaymentList(payment);
        ExcelUtil<Payment> util = new ExcelUtil<Payment>(Payment.class);
        util.exportExcel(response, list, "付款数据");
    }

    /**
     * 获取付款详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:payment:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(paymentService.selectPaymentById(id));
    }


    /**
     * 查询详情
     */
    @PreAuthorize("@ss.hasPermi('business:payment:query')")
    @GetMapping(value = "/getDetail/{id}")
    public AjaxResult getDetail(@PathVariable("id") Long id)
    {
        return success(paymentService.getDetail(id));
    }


    /**
     * 新增付款
     */
    @PreAuthorize("@ss.hasPermi('business:payment:add')")
    @Log(title = "付款", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult add( @RequestBody Payment payment)
    {
        return toAjax(paymentService.insertPayment(payment));
    }

    /**
     * 完成付款
     */
    @PreAuthorize("@ss.hasPermi('business:payment:finish')")
    @Log(title = "完成付款", businessType = BusinessType.INSERT)
    @PostMapping("/finish")
    public AjaxResult finish( PaymentFinishReqParam param)
    {
        return toAjax(paymentService.finish(param));
    }

    /**
     * 提交付款
     */
    @PreAuthorize("@ss.hasPermi('business:payment:submit')")
    @Log(title = "提交付款审核", businessType = BusinessType.INSERT)
    @PostMapping("/submit")
    public AjaxResult submit(@RequestBody Payment payment)
    {
        return toAjax(paymentService.submit(payment));
    }



    /**
     * 修改付款
     */
    @PreAuthorize("@ss.hasPermi('business:payment:edit')")
    @Log(title = "付款", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Payment payment)
    {
        return toAjax(paymentService.updatePayment(payment));
    }

    /**
     * 删除付款
     */
    @PreAuthorize("@ss.hasPermi('business:payment:remove')")
    @Log(title = "付款", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(paymentService.deletePaymentByIds(ids));
    }
}
